package com.macro.mall.portal.config;

import com.easemob.im.ApiClient;
import com.easemob.im.ApiException;
import com.easemob.im.api.ContactApi;
import com.easemob.im.api.UserApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class IMConfig {

    @Bean
    public ApiClient easemobApiClient() throws ApiException {
        ApiClient client = ApiClient.builder()
                .setBasePath("https://a1-sgp.easemob.com")
                .setAppKey("1179251103209008#seamanmall")
                .setClientId("YXA6-aa_alt_SzuNspZTSpbpnw")
                .setClientSecret("YXA6tz6camJOLzTKkUw3svIhntJqkvI")
                .build();

        com.easemob.im.Configuration.setDefaultApiClient(client);
        return client;
    }

    @Bean
    public UserApi userApi(ApiClient easemobApiClient) {
        UserApi api = new UserApi();
        api.setApiClient(easemobApiClient);  // 必须手动设置！
        return api;
    }

    @Bean
    public ContactApi contactApi(ApiClient easemobApiClient) {
        ContactApi contactApi = new ContactApi();
        contactApi.setApiClient(easemobApiClient);  // 必须手动设置！
        return contactApi;
    }

}
